package com.itita.weibo.db;

import java.util.Date;

import weibo4andriod.RetweetDetails;
import weibo4andriod.Status;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import android.database.sqlite.SQLiteOpenHelper;

public final class DataBaseOpenHelpler extends SQLiteOpenHelper{
	 
	public static final String TIME_OF_ODERY_NAME = "time desc";
	
	public static final String WEIGHT_OF_ODERY_NAME = "weight desc";
	
	private static final String DBNAME  = "itita_weibo";
	 
	private static final int version  = 1;
	
	public DataBaseOpenHelpler(Context context){
		super(context, DBNAME, null, version);
	}
	
	
	/** 如果数据不存在是调用 ***/
	@Override
	public void onCreate(SQLiteDatabase db) {
		 StringBuffer sbSql = new StringBuffer();
			sbSql.append("CREATE TABLE IF NOT EXISTS t_user( ")
			       .append("id integer primary key autoincrement, ")
			       .append("username TEXT, ")  //用户名
			       .append("islogin INTEGER, ")//是否是登陆账号
			       .append("password TEXT,")  //登陆密码
			       .append("userid TEXT,") //用户ID
			        .append("name TEXT ,") //用户ID

		     .append("accessToken TEXT,") //访问Token
		     .append("accessTokenSecret TEXT )"); //访问TokenSecret
			
			//执行SQL语句
			db.execSQL(sbSql.toString());
			  
			sbSql.delete(0, sbSql.length());   
			  sbSql.append("CREATE TABLE IF NOT EXISTS home_table(")
				 .append("id integer primary key autoincrement, ")
				 .append("statusid TEXT,") //statusId
				 .append("uid TEXT, ") //发微薄的人 userId
				 .append("nick TEXT,")  //发微薄人的昵称
		         .append("portrait TEXT,") //发微薄用户的头像地址
				 .append("vip INTEGER, ")  //时候是ViP 用户
				 .append("content TEXT, ") //微博内容
				 .append("pic TEXT, ")  //微博的图片地址
				 .append("time TEXT, ") //发布时间
				 
				 .append("rtstatusid TEXT,") //rtstatusId
				 .append("rtrootuid TEXT, ") //转发微博 用户的ID
		         .append("rtrootnick TEXT,")   
				 .append("rtrootvip INTEGER, ") 
				 .append("rtreason TEXT,  ") 
				 
				 .append("rtnum INTEGER, ") //转发数量
				 .append("commentnum INTEGER, ") //评论数量
				 
				 .append("src TEXT,")  //微博来源
				 .append("longitude TEXT,")
				 .append("latitude TEXT,")
			     
				 .append("weight TEXT ,")//微博信息权值
			  
			     .append("userid TEXT ,") //用ID --->相当于外键关联
			  
			     .append("fansNum TEXT,")  //粉丝数
			     .append("attentionNum TEXT,")  //关注数
			     .append("statusNum TEXT )") ; //微博数
			     
			  
			  
				//执行SQL语句
				  db.execSQL(sbSql.toString());
	}
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
			db.execSQL("DROP TABLE IF EXISTS t_user");
			db.execSQL("DROP TABLE IF EXISTS home_table");
			onCreate(db);
	}

}
